package com.rtf.framework.es.common;

import lombok.Data;
import lombok.ToString;

import java.util.List;

/**
 * @Classname AppEsPage
 * @Description TODO
 * @Date 2021/1/12 7:08 上午
 * @Created by lizhen
 */
@Data
@ToString
public class AppEsPage<T> {

    /**
     * 当前页
     */
    private int currentPage;

    /**
     * 每页显示多少条
     */
    private int pageSize;

    /**
     * 总记录数
     */
    private int totailCount;

    /**
     * 总页数
     */
    private int totalPages;
    /**
     * 本页的数据列表
     */
    private List<T> recordList;

    /**
     * 只接受前4个必要的属性，会自动的计算出其他3个属性的值
     *
     * @param currentPage
     * @param pageSize
     * @param totailCount
     * @param recordList
     */
    public AppEsPage(int currentPage, int pageSize, int totailCount, List<T> recordList) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totailCount = totailCount;
        this.recordList = recordList;
    }

    public int getTotalPages() {
        return this.pageSize == 0 ? 1 : (int)Math.ceil((double) this.totailCount / (double) this.pageSize);
    }
}

